from .models import *
from rest_framework.serializers import ModelSerializer


class CourseCategorySerializer(ModelSerializer):
    class Meta:
        model = CourseCategory
        fields = ['id', 'name']


class TeacherSerializer(ModelSerializer):
    class Meta:
        model = Teacher
        fields = ['name', 'role_name', 'title', 'signature', 'image', 'brief']


class CourseSerializer(ModelSerializer):
    teacher = TeacherSerializer()

    class Meta:
        model = Course
        fields = [
            'id',
            'name',
            'course_img',
            'price',
            'students',
            'pub_sections',
            'sections',

            # 列表页面不显示，详情接口会显示
            'period',  # 建议学习周期
            'brief',
            'attachment_path',  # 文档地址

            'course_type_name',
            'level_name',
            'status_name',
            # 关联表
            'teacher',
            'section_list',  # 返回课时
        ]


class CourseSectionSerializer(ModelSerializer):
    class Meta:
        model = CourseSection
        fields = ['id', 'name', 'orders', 'section_link', 'duration', 'free_trail']


class CourseChapterSerializer(ModelSerializer):
    coursesections = CourseSectionSerializer(many=True)

    class Meta:
        model = CourseChapter
        fields = ['id', 'name', 'chapter', 'summary', 'coursesections']


class CourseDetailSerializer(ModelSerializer):
    teacher = TeacherSerializer()
    coursechapters = CourseChapterSerializer(many=True)

    class Meta:
        model = Course
        fields = [
            'id',
            'name',
            'course_img',
            'price',  #
            'students',
            'pub_sections',  # 发布多少课时
            'sections',

            # 列表页面不显示，详情接口会显示
            'period',  # 建议学习周期
            'brief',
            'attachment_path',  # 文档地址

            # choice字段,定制返回格式--》表模型中写
            'course_type_name',
            'level_name',
            'status_name',
            # 关联表
            'teacher',  # teacher 所有数据---》子序列化
            'coursechapters',  # 所有章节
        ]
